package com.neusoft.demo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;

import com.neusoft.demo.dao.GouwucheMapper;
import com.neusoft.demo.po.Gouwuche;
import com.neusoft.demo.utils.SqlSessionFactoryUtil;

@WebServlet("/ChangeNumFormGouWuCheServlet")
public class ChangeNumFormGouWuCheServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 获取购物车ID和数量
		Integer catid = Integer.valueOf(request.getParameter("catid"));
		Integer num = Integer.valueOf(request.getParameter("num"));
		// 新建购物车实体类，并赋值
		Gouwuche gouwuche = new Gouwuche();
		gouwuche.setCatid(catid);
		gouwuche.setNum(num);
		// 创建SqlSession对象
		SqlSession session = SqlSessionFactoryUtil.getSqlSessionFactory().openSession();
		// 生成代理类
		GouwucheMapper gouwucheMapper = session.getMapper(GouwucheMapper.class);
		// 修改数量
		gouwucheMapper.updateGouwuche(gouwuche);
		// 提交事务
		session.commit();
		session.close();
	}

}
